function defaultImgDeal (el, binding) {
  const type = binding.arg ? binding.arg : 'head'
  let defaultImg = 'http://onmxkx5tf.bkt.clouddn.com/default-head.png'
  if (type === 'poster') {
    defaultImg =
      'https://bpic.588ku.com/element_pic/01/47/02/12574338a640011.jpg'
  }
  if (binding.value) {
    defaultImg = binding.value
  }
  if (!el.src) {
    el.src = defaultImg
  }
  el.onerror = () => {
    el.src = defaultImg
  }
}

const directives = {
  autoOrient: {
    bind: el => {
      el.src = el.src + '?imageMogr2/auto-orient'
    }
  },
  defaultImg: {
    bind: (el, binding) => {
      defaultImgDeal(el, binding)
    },
    update: (el, binding) => {
      defaultImgDeal(el, binding)
    }
  }
}

export default {
  install (vue, options) {
    for (const key in directives) {
      vue.directive(key, directives[key])
    }
  }
}
